//
//  VKNickIphoneController.m
//  V-Learn
//
//  Created by liubo on 2019/1/15.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKNickController.h"

@interface VKNickController ()
@property (nonatomic, strong) UITextField *editTf;
@end

@implementation VKNickController

-(UITextField *)editTf{
    if (_editTf == nil) {
        _editTf = [[UITextField alloc]init];
    }
    return _editTf;
}
- (instancetype)initWithRow:(NSInteger)row;
{
    self = [super init];
    if (self) {
        self.row = row;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
    self.edgesForExtendedLayout = @[];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    
    [self.view addSubview:self.editTf];
    self.editTf.backgroundColor = [UIColor whiteColor];
    UIView *leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 15, 10)];
    self.editTf.clearButtonMode = UITextFieldViewModeAlways;
    self.editTf.leftViewMode = UITextFieldViewModeAlways;
    self.editTf.leftView = leftView;
    [self.editTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.height.equalTo(@53);
        make.top.mas_equalTo(@15);
    }];
    
    if (self.row == 0) {
        self.editTf.placeholder = @"请输入昵称";
    }else if (self.row == 3){
        self.editTf.placeholder = @"请输入手机号";
    }
    [self setupRightItem];
}
// 右边Item
- (void)setupRightItem{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"确定" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [button setTitleColor:[UIColor cz_colorWithRed:40 green:40 blue:40] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button] ;
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@30);
        make.width.equalTo(@70);
    }];
    [button addTarget:self action:@selector(buttonItemClick) forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonItemClick{
    NSString *content = [self.editTf.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    if ((content.length == 0) || [content isEqualToString:@""]) {
        [MBProgressHUD showSuccess:@"请输入昵称" toView:self.view];
        return;
    }
    
    if (_infoBlock) {
        self.infoBlock(content);
        [self.navigationController popViewControllerAnimated:YES];
    }
}
@end
